package com.niit.service;

import com.niit.bo.PageBean;
import com.niit.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王铭 20181620310021
 * #Date 2021/6/25 - 23:39
 */
@Service
public class ExamService {

    StudentService service;

    @Autowired
    public void setService(StudentService service) {
        this.service = service;
    }

    public PageBean<PaperQuestion> doPaper(Long paperID, Student student, int integer) {

        ExamPaper examPaper = service.getExamPaperById(paperID);
//        List<ExamPaper> examPaper = service.list(new Long(paperID));


        PageBean<PaperQuestion> pageBean = new PageBean<>(examPaper.getPaperQuestions().size(), 1, integer);

        pageBean.setArrayList(examPaper.getPaperQuestions().subList(pageBean.getLimitDown(), pageBean.getLimitUp()));
        return pageBean;
//        ArrayList<PaperQuestion> paperQuestions=new ArrayList<PaperQuestion>();
//        PaperQuestion paperQuestion=new PaperQuestion();
//        Question question=new Question();
//        question.setSelections(new ArrayList<Selection>());
//        paperQuestion.setQuestion(question);
//        paperQuestions.add(paperQuestion);
//        pageBean.setArrayList(paperQuestions);
    }

    public PageBean<PaperQuestion> doPaper(Long paperID, Student student, Integer q_next, StudentPaperQuestionAnswer studentPaperQuestionAnswer) {
        studentPaperQuestionAnswer.setId_student(student.getId_student());

        if (service.add(studentPaperQuestionAnswer).equals("fail"))
            if (service.update(studentPaperQuestionAnswer).equals("fail"))
                System.out.println("888888888888存储答题失败888888888888888");

        ExamPaper examPaper = service.getExamPaperById(paperID);

        PageBean<PaperQuestion> pageBean = new PageBean<>(examPaper.getPaperQuestions().size(), 1, q_next);

        pageBean.setArrayList(examPaper.getPaperQuestions().subList(pageBean.getLimitDown(), pageBean.getLimitUp()));
        return pageBean;
    }
}
